﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using CyclingRoutes.Models;

namespace CyclingRoutes.Controllers
{
    public class RouteController : Controller
    {
        private RouteRepository _repository;
        public RouteController()
        {
            _repository=new RouteRepository();
        }

        public ActionResult List()
        {
            var routes = _repository.GetTopRoutes();
            return View(routes);
        }

        public ActionResult Details(string name)
        {
            var route = _repository.GetRoute(name);
            if (route != null)
                return View(route);
            return RedirectToAction("RouteNotFound");
        }

        public ActionResult RouteNotFound()
        {
            return View();
        }
    }
}
